var utils = require("../utils/utils");
var ocr_utils = require("../utils/ocr_utils");
var ad = require("./ad");
var in_task = require("./inTask");
var point_map = require("./pointMap");

var watch_video = {
  go_page_from_home() {
    var logger = utils.create_logger("watch_video go_page_from_home: ");
    // utils.click_point.apply(
    //   utils,
    //   utils.get_size_point(point_map["首页我的"], 1080, 2340)
    // );
    // sleep(utils.get_random_interval(2, 0, 1, 1000));
    // var ocr_text = ocr_utils.screen_exists_text_one(["去赚现金", "点我领钱"]);
    // if (ocr_text) {
    //   console.log("找到-去赚现金或点我领钱");
    //   utils.click_ocr_text(ocr_text);
    //   sleep(utils.get_random_interval(4, 0, 1, 1000));
    //   var interval = utils.get_random_interval(6, 0, 2, 1000);
    //   logger("等待--" + interval / 1000 + "--秒后开始判断是否开宝箱");
    //   sleep(interval);
    this.init();
    // } else {
    //   console.log("没找到-去赚现金或点我领钱");
    // }
  },
  init() {
    console.log("watch_video init");
    var ocr_text = ocr_utils.screen_exists_text_one("立即领取", false);
    if (ocr_text) {
      console.log("watch_video go_page_from_home: 找到--立即领取--");
      utils.click_ocr_text(ocr_text);
      sleep(utils.get_random_interval(2, 0, 2, 1000));
      this.run();
    } else {
      console.log("watch_video go_page_from_home: 没找到--立即领取--");
      this.after();
    }
  },
  run() {
    ad.has_watch_ad_times = 0;
    ad.init();
    this.after();
  },
  after() {
    console.log("watch_video after");
    if (utils.click_text_starts_with("开心收下")) {
      sleep(utils.get_random_interval(2, 0, 2, 1000));
    }
    // this.next();
  },
  next() {
    console.log("watch_video next");
  },
};
